/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include <xml/Stream.h>
#include <xml/Saver.h>
#include "Shaders.h"
#include <algorithm>
#include <safe_new.h>

namespace liba
{
namespace lib3d
{
namespace material
{

Shaders::Shaders(const Atom & name)
:	animate::Node( name )
{}

Shaders::Shaders(const Shaders & other)
:	animate::Node(other)
{
	const_iterator it = other.begin();
	for( ; it != other.end(); ++ it )
	{
		push_back( new Shader(**it) );
	}
}

animate::Node * Shaders::find_animate_node(const Atom & name, bool recursion)
{
	iterator it = begin();
	for( ; it != end(); ++ it )
	{
		if( (*it)->GetName() == name )
			return *it;
		if( recursion )
		{
			animate::Node * node = (*it)->FindAnimateNode( name, recursion );
			if ( node )
				return node;
		}
	}
	return 0;
}

bool Shaders::on_node(xml::Provider *prov, const std::string & name)
{
	if( name == "Shader" )
	{
		push_back( new Shader() );
		return prov->parse_object( back() );
	}
	return false;
}

} // namespace material
} // namespace lib3d
} // namespace liba

